<?php
header("Access-Control-Allow-origin:*");
require_once "PluploadHandler.php";

$base_path = substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], '/plupload'));
$path = $_SERVER['DOCUMENT_ROOT'] . (substr($base_path, 0, 1) == "/" ? "" : "/") . "uploads" . DIRECTORY_SEPARATOR . date("Ymd");

$ph = new PluploadHandler(array(
    'target_dir' => $path,
    'file_data_name' => 'img',
    // 'target_dir' => "../uploads/ss",
    'allow_extensions' => 'jpg,jpeg,png,zip'
));

$ph->sendNoCacheHeaders();
$ph->sendCORSHeaders();
$rand=mt_rand(0,1);


if ($result = $ph->handleUpload()) {
    if($rand){
        $result["src"] = (substr($base_path, 0, 1) == "/" ? "" : "/") . "uploads" . DIRECTORY_SEPARATOR . date("Ymd") . DIRECTORY_SEPARATOR . $result["name"];
    $result["full_src"] ="https://wnworld.com".(substr($base_path, 0, 1) == "/" ? "" : "/") . "uploads" . DIRECTORY_SEPARATOR . date("Ymd") . DIRECTORY_SEPARATOR . $result["name"];
    die(json_encode(array(
        'status' => 1,
        'data'=>array(
            'url' =>$result["src"],
            'full_url'=>$result["full_src"]
        )
    )));
}else{
    die(json_encode(array(
        'status' => 0,
        'msg'=>"上传失败"
    )));
}

   
} else {
    die(json_encode(array(
        'status' => 0,
        'msg'=>"上传失败"
    )));
}